#include "gamehall.h"
#include "ui_gamehall.h"
#include<QPainter>
#include<QIcon>
#include<QFont>
#include<QPushButton>
#include"gameselect.h"
#include<QSound>


GameHall::GameHall(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::GameHall)
{
    ui->setupUi(this);
    this->setFixedSize(1500,1000);//设置窗口大小
    this->setWindowTitle(QString("贪吃蛇游戏"));
    this->setWindowIcon(QIcon(":res/ico.png"));//设置窗口图标
    //
    QFont font("华文行楷",20);
    QPushButton * strbutton = new QPushButton(this);
    strbutton->setText("开始游戏");
    strbutton->setFont(font);
    strbutton->move(650,700);
    strbutton->setShortcut(QKeySequence(Qt::Key_Space));
    strbutton->setStyleSheet("QPushButton{border:0px}");//给按钮设置样式  去除边框


    GameSelect *  gameSelect = new GameSelect;
    connect(strbutton,&QPushButton::clicked,[=](){
        this->close();//当前窗口关闭
        gameSelect->setGeometry(this->geometry());//设置第二个窗口于当前窗口一致
        gameSelect->show();//新的窗口打开
        QSound::play(":res/clicked.wav");
    });
}


GameHall::~GameHall()
{
    delete ui;

}

void GameHall::paintEvent(QPaintEvent *event)
{
    //实例化画家对象
     QPainter painter(this);

     //实例化绘图设备
     QPixmap pix(":res/game_hall.png");

     //绘画
     painter.drawPixmap(0,0,this->width(),this->height(),pix);

}

